﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;


namespace AlphaSolutionsGP
{
    public class Event
    {
        //MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");  

        #region Properties
        //even ID
        private int eventId;
        //personal tutorial ID
        private int ptID;
        //ID of the student for the event, if any
        private string studentId;
        //ID of the staff for the event, if any
        private string staffId;     
        //Name of the event
        private string eventName;
        //Description to say what the event is for
        private string description;
        //Date of the event
        private string eventDate;
        //Time of the event
        private string eventTime;
        //an indication of how urgent the event is
        private string priority;
        // the status of the personal tutorial
        private string status;
        //the term in which the personal tutorial takes takes place
        private string term;
        #endregion

        #region constructors
        //default constructor
        public Event()
        {
            eventName = "";
            description = "";
            eventDate = "";
            eventTime = "";
            priority = "";
            studentId = "";
            staffId = "";
        }

        public Event(int id, string name, string desc, string Date, string time, string priority, string staffID, string studentID)
        {
            this.eventId = id;
            this.eventName = name;
            this.description = desc;
            this.eventDate = Date;
            this.eventTime = time;
            this.priority = priority;
            this.staffId = staffID;
            this.studentId = studentID;
        }

        //this is the constructor when a personal tutorial needs to be enither viewed or amended
        public Event(int id, string name, string desc, string Date, string time, string priority, string staffID, string studentID, string status, string term)
        {
            this.ptID = id;
            this.eventName = name;
            this.description = desc;
            this.eventDate = Date;
            this.eventTime = time;
            this.priority = priority;
            this.staffId = staffID;
            this.studentId = studentID;
            this.status = status;
            this.term = term;
        }


        #endregion

        #region Methods
        public void createEvent()
        {
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                frmStudentProfile form = new frmStudentProfile();
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "insert into EVENT(name, description, date, time, priority, STUDENT_student_ID, STAFF_staff_ID) values('" + eventName + "','" + description + "','" + eventDate + "','" + eventTime + "','" + priority + "','" + studentId + "','" + staffId + "');";
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Event has been inserted.","Insert OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to insert due to the following error:\n\n" + ex.ToString());
            }
        }

        public void amendEvent()
        { 
            //connection string to be added here
            //command
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "UPDATE EVENT SET name='"+eventName+"', description='"+description+"', date='"+eventDate+"', time='"+eventTime+"', priority='"+priority+"', STUDENT_student_id='"+studentId+"', STAFF_staff_id='"+staffId+
                    "' WHERE event_ID="+eventId;
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Event has been modified.", "Modify OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to modify due to the following error:\n\n" + ex.ToString());
            }
        }

        public void removeEvent()
        {
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "DELETE FROM EVENT WHERE event_ID="+eventId;
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Event has been deleted.", "Delete OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to delete due to the following error:\n\n" + ex.ToString());
            }
        }

        public void removePersonalTutorial()
        {
            MySqlConnection connection = new MySqlConnection("server=194.81.104.22;" + "User Id=alpha;" + "database=alpha_db;" + "password=bravo;");
            try
            {
                connection.Open();
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Connection failed");
            }
            try
            {
                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "DELETE FROM PERSONAL_TUTORIAL WHERE pt_ID=" + personalTutorialID;
                MySqlDataReader run = cmd.ExecuteReader();
                System.Windows.Forms.MessageBox.Show("The Personal Tutorial has been deleted.", "Delete OK", System.Windows.Forms.MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Unable to delete due to the following error:\n\n" + ex.ToString());
            }
        }

        //method to copy data from one event to another
        public void copyEvent(Event copy)
        {
            this.studentId = copy.studentId;
            this.staffId = copy.staffId;
            this.eventName = copy.eventName;
            this.description = copy.description;
            this.eventDate = copy.eventDate;
            this.eventTime = copy.eventTime;
            this.priority = copy.priority;
        }
        #endregion

        #region getters and setters
        public string Priority
        {
            get { return priority; }
            set { priority = value; }
        }

        public int eventID
        {
            get { return eventId; }
            set { eventId = value; }
        }

        public int personalTutorialID
        {
            get { return ptID; }
            set { ptID = value; }
        }

        public string studentID
        {
            get { return studentId; }
            set { studentId = value; }
        }


        public string staffID
        {
            get { return staffId; }
            set { staffId = value; }
        }
        public string EventTime
        {
            get { return eventTime; }
            set { eventTime = value; }
        }
     
        public string Date
        {
            get { return eventDate; }
            set { eventDate = value; }
        }
        
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        
        public string EventName
        {
            get { return eventName; }
            set { eventName = value; }
        }

        public string Status
        {
            get { return status; }
            set { status = value; }
        }

        public string Term
        {
            get { return term; }
            set { term = value; }
        }

        #endregion






    }
}
